using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using Commons;
using WPFBPMN;
using WPFBPMN.Utils;
namespace CustomControls
{
    public class BPMNPool : BPMNContainer
    {
        public override Brush Background
        {
            get
            {
                return DrawingCanvas.Background;
            }
            set
            {
                DrawingCanvas.Background = value;
                base.Background = value;
            }
        }
        public BPMNPool(BPMNShape parent, List<string> additionalArguments)
            : base(parent)
        {


            BPMNShapeType = ShapeType.BPMNPool;
            CanBeUnlocked = false;
            LockMoving = true;
            Canvas.SetLeft(this, 10);



        }

        public override void BPMNInitialize()
        {
            base.BPMNInitialize();
            Title.BorderBrush = Brushes.Black;
            Title.BorderThickness = new Thickness(0, 0, 0, 1);
            Rectangle border = new Rectangle();
            border.StrokeThickness = 1;
            border.StrokeLineJoin = PenLineJoin.Round;
            border.Stroke = Brushes.Black;
            Canvas.SetTop(border, 0);
            Canvas.SetLeft(border, 0);

            Binding binding = new Binding();
            binding.Source = this;
            binding.Path = new PropertyPath(BPMNShape.WidthProperty);
            border.SetBinding(Rectangle.WidthProperty, binding);


            binding = new Binding();
            binding.Source = this;
            binding.Path = new PropertyPath(BPMNShape.HeightProperty);
            border.SetBinding(Rectangle.HeightProperty, binding);

            (this as Canvas).Children.Insert(0, border);
            border.IsHitTestVisible = false;

            if (ShapeParent != null)
            {
                ArangeChildren();
            }
            Width = 800;
            Height = 200;


            WindowMain.DrawingToBuild = ShapeType.BPMNLane;
            CreateNewDrawing(null);

        }
        public override void ArangeChildren()
        {
            if (ShapeParent != null && ShapeParent.Children.Count > 0)
            {
                
                Canvas.SetTop(ShapeParent.Children[0], 10);
                BPMNShape previousShape = null;
                
                for (int i = 1; i < ShapeParent.Children.Count; i++)
                {
                    previousShape = ShapeParent.Children[i - 1] as BPMNShape;
                    Canvas.SetTop(ShapeParent.Children[i], Canvas.GetTop(previousShape) + previousShape.Height+20);
                    previousShape.Width = ShapeParent.Width - 20;
                }
                previousShape = ShapeParent.Children[ShapeParent.Children.Count - 1] as BPMNShape;
                previousShape.Width = ShapeParent.Width - 20;
            }
        }
    }
}
